/**
 * 项目名：泰禾资产
 * 包名：com.pactera.vo.common
 * 文件名：BaseRespPageVo.java
 * 版本信息：1.0.0
 * 日期：2019年1月11日-下午11:10:16
 * Copyright (c) 2019 Pactera 版权所有
 */
 
package com.pactera.vo.common;

import java.util.Collection;
import java.util.List;

import org.apache.poi.ss.formula.functions.T;

import com.github.pagehelper.Page;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @ClassName：BaseRespPageVo
 * @Description：Page响应基类
 * @author LiuGuiChao 
 * @date 2019年1月11日 下午11:10:16 
 * @version 1.0.0 
 */
@SuppressWarnings("hiding")
@ApiModel(value="page信息基类Vo",description="page信息基类Vo")
public class PageRespVo<T> {
	
	@ApiModelProperty(value="当前页码", name="pageNo", required=true)
	protected Integer pageNo;
	
	@ApiModelProperty(value="数据容量",name="pageSize")
	protected Integer pageSize;
	
	@ApiModelProperty(value="总共页数",name="totalPages")
	protected Integer totalPages;
	
	@ApiModelProperty(value="数据总量",name="totalCount")
	protected Long totalCount;
	
	@ApiModelProperty(value="结果集",name="list")
	protected List<T> list;
	
	@ApiModelProperty(value="是否为第一页",name="totalCount")
	protected boolean isFirstPage = false;
	
	@ApiModelProperty(value="是否为最后一页",name="totalCount")
	protected boolean isLastPage = false;
	
	public PageRespVo() {}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public PageRespVo(List<T> list) {
       if (list instanceof Page) {
           Page page = (Page) list;
           this.pageNo = page.getPageNum();
           this.pageSize = page.getPageSize();
           this.totalPages = page.getPages();
           this.totalCount = page.getTotal();
           this.list = page;
       } else if (list instanceof Collection) {
           this.pageNo = 1;
           this.pageSize = list.size();
           this.totalPages = 1;
           this.totalCount = Integer.toUnsignedLong(list.size());
           this.list = list;
       }
       if (list instanceof Collection) {
           judgePageBoudary();
       }
   }

   /**
	* @Title: judgePageBoudary 
	* @Description: 判断页面边界
	* @author LiuGuiChao
	* @date 2019年1月11日 下午11:54:47 
	*/
    private void judgePageBoudary() {
	    isFirstPage = pageNo == 1;
	    isLastPage = pageNo == pageSize;
    }

	/**
	 * @return the pageNo
	 */
	public Integer getPageNo() {
		return pageNo;
	}
	
	/**
	 * @param pageNo the pageNo to set
	 */
	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}
	
	/**
	 * @return the pageSize
	 */
	public Integer getPageSize() {
		return pageSize;
	}
	
	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	
	/**
	 * @return the totalPages
	 */
	public Integer getTotalPages() {
		return totalPages;
	}
	
	/**
	 * @param totalPages the totalPages to set
	 */
	public void setTotalPages(Integer totalPages) {
		this.totalPages = totalPages;
	}
	
	/**
	 * @return the totalCount
	 */
	public Long getTotalCount() {
		return totalCount;
	}
	
	/**
	 * @param totalCount the totalCount to set
	 */
	public void setTotalCount(Long totalCount) {
		this.totalCount = totalCount;
	}
	
	/**
	 * @return the isFirstPage
	 */
	public boolean isFirstPage() {
		return isFirstPage;
	}
	
	/**
	 * @param isFirstPage the isFirstPage to set
	 */
	public void setFirstPage(boolean isFirstPage) {
		this.isFirstPage = isFirstPage;
	}
	
	/**
	 * @return the isLastPage
	 */
	public boolean isLastPage() {
		return isLastPage;
	}
	
	/**
	 * @param isLastPage the isLastPage to set
	 */
	public void setLastPage(boolean isLastPage) {
		this.isLastPage = isLastPage;
	}

	/**
	 * @return the list
	 */
	public List<T> getList() {
		return list;
	}

	/**
	 * @param list the list to set
	 */
	public void setList(List<T> list) {
		this.list = list;
	}

	@Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("PageInfo{");
        sb.append("pageNum=").append(pageNo);
        sb.append(", pageSize=").append(pageSize);
        sb.append(", total=").append(totalPages);
        sb.append(", pages=").append(totalCount);
        sb.append(", list=").append(list);
        sb.append(", isFirstPage=").append(isFirstPage);
        sb.append(", isLastPage=").append(isLastPage);
        sb.append(", navigatepageNums=");
        sb.append('}');
        return sb.toString();
    }
}
